package com.xiaolin.web.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName HelloInterceptor
 * @Description TODO
 * @Detail 拦截器
 * @Author MyPC
 * @Date 2020/9/28
 * @Version 1.0
 */
@Component
public class HelloInterceptor implements HandlerInterceptor{
    /**
     * 请求拦截
     * @param request
     * @param response
     * @param handler
     * @return
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        //返回false则拦截掉请求，返回true则放行
        System.out.println("HelloInterceptor放行");
        return true;
    }

    /**
     * 处理请求
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
        System.out.println("HelloInterceptor被调用");
    }

    /**
     * 响应拦截
     * @param request
     * @param response
     * @param handler
     * @param ex
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        System.out.println("HelloInterceptor回去吧");
    }
}
